package top.zhangjianyong.test.rule;


import top.zhangjianyong.test.entity.Game;
import top.zhangjianyong.test.entity.People;

public class GameRule1 implements GameRule {

    public void start(Game game) throws Exception {

        People people1 = game.getPeople1();
        People people2 = game.getPeople2();

        // System.out.println("-----------start-------------");

        while (people1.hasNextCoin() && people2.hasNextCoin()) {

            boolean status1 = people1.nextCoin().isStatus();
            boolean status2 = people2.nextCoin().isStatus();


            if (status1 && status2) {
                people1.addToIncome(3);
                people2.addToIncome(-3);
            } else if (!status1 && !status2) {
                people1.addToIncome(1);
                people2.addToIncome(-1);
            } else {
                people1.addToIncome(-2);
                people2.addToIncome(2);
            }

        }
        //System.out.println("-------------end--------------");
        if (people1.getIncome() > people2.getIncome()) {
            people1.win();
        } else if (people1.getIncome() < people2.getIncome()) {
            people2.win();
        }
        // System.out.println(people1.toString());
        //System.out.println(people2.toString());
    }
}
